(function () {
    //查询
    jQuery('.app-btn-search').on('click',function(){
        serverData.key=jQuery("#search").val();
        serverTable.draw();
    });
    //撤销查询
    jQuery('.app-btn-cancel').on('click',function(){
        jQuery('#search').val('');
        serverData.key='';
        serverTable.draw();
    });
	
    var serverData = {};
    var serverTable;
    jQuery(document).ready(function () {
        serverTable = jQuery('#dataTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/kitchenwaste/getpage',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [
                {
                data: null
                },
                {
                    data: 'waste'
                },
                {
                    data: 'wasteOil'
                },
                {
                    data: 'remark'
                },
                {
                    data: 'businesssellerBaseInfo.shopName'
                },
                {
                    data: 'checkPerson.name'
                },
                {
                    data: 'createTime',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD HH:mm');
                        else
                            return '';
                    }
                }  
              ],
				"drawCallback" : function(oSettings) {
					var k = 0;
					var total = oSettings.aiDisplay.length
							+ oSettings._iDisplayStart;

					for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
						$(
								'td:eq(0)',
								oSettings.aoData[oSettings.aiDisplay[k]].nTr)
								.text(i + 1);
						k++;
					}

					serverTable.off('click', 'tr');
					serverTable
							.on(
									'click',
									'tr',
									function(event) {
										event = event
												|| window.event;
										var target = event.target
												|| event.scrElement;
										var data = serverTable
												.row(
														this)
												.data();

										if (target.className
												.indexOf('fa-remove') != -1
												|| target.className
														.indexOf('delBtn') != -1) {

											deleteModule(data);
										}

										if (target.className
												.indexOf('fa-pencil') != -1
												|| target.className
														.indexOf('editBtn') != -1) {

											editModule(data);
										}

										return;
									});
				}
        });
    });
    
})();